package qc.module.sl.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import qc.module.sl.entity.SlBasicProjectRelation;
import qc.module.sl.repository.SlBasicProjectRelationRepository;

import java.util.ArrayList;
import java.util.List;

/**
 * BasicProjectRelationService
 *
 * @author QuCheng Tech
 * @create 2023/02/15
 */
@Service
public class BasicProjectRelationService {
    private SlBasicProjectRelationRepository repository;
    
    @Autowired
    public void setSlBasicProjectRelationRepository(SlBasicProjectRelationRepository repository){
        this.repository = repository;
    }
    
    /**
     * 根据输入的分类编码获取工程id
     * 
     * @param	classifyCode	分类编码
     * @return 工程id集合
     * @author QcCheng Tech
     * @since 2023/2/15
     */
    public List<Integer> queryProjectIdByClassifyCode(String classifyCode){
        if (!StringUtils.isBlank(classifyCode)){
            LambdaQueryWrapper<SlBasicProjectRelation> wrapper = new LambdaQueryWrapper<>();
            
            wrapper.select(SlBasicProjectRelation::getProjectid);
            
            wrapper.eq(SlBasicProjectRelation::getClassifycode , classifyCode);
            wrapper.orderByAsc(SlBasicProjectRelation::getProjectid);
            
            List<SlBasicProjectRelation> list = repository.selectList(wrapper);
            
            if (list.size() > 0x0){
                List<Integer> result = new ArrayList<>();
                for (int i = 0; i < list.size() ; i++) {
                    result.add(list.get(i).getProjectid());
                }
                return result;
            }
        }
        return null;
    }
}
